Babun一个在Windows下面的Shell神器

1. 简介

1.1. Babun是什么

Babun是Windows上的一个第三方Shell,在这个Shell上面你可以使用几乎所有Linux、Unix的命令,它几乎可以取代Windows上的Shell。用官方的题目说就是A Windows shell you will love!

Babun是近年来最好的在Windows下使用Linux Shell的一站式解决方案。Babun虽然没有多少技术创新,但是它博采众长,追求极致的体验,把其它同类软件狠狠地甩在了后面。无论是被迫使用Windows的Linuxer,还是离不开Windows却又羡慕Linux下强大的命令行工具的PC用户,Babun都是一个不容错过的好东西,相信你会爱上它。

在之前,前辈们为我们留下了一个叫做Cygwin的软件集,让我们在需要的时候可以从Windows上启动bash,安装常见的自由软件。虽然Cygwin号称Get that Linux felling on Windows,给人的感觉却一点都不Linux。幸运的是,我们现在有了Babun这个在Windows上的开销即用的工具,它基于Cygwin,却胜过Cygwin。

1.2. Babun的特性

Babun的特性:

  • 预先配置好的Cygwin以及一系列插件
  • pact:一个类似于apt-getyum的包管理器
  • 预先配置好的gitshell(zsh+bash)
  • 集成oh-my-zsh
  • 一键安装,不需要任何admin权限
  • 带有xTerm-256兼容的终端(console)
  • 支持HTTP(s)代理
  • 组件化的架构
  • 自动更新
  • 在右键菜单(context menu)中集成了”Open Babun Here”的入口

2. 安装体验

2.1. 安装

先从官网下载最新的 Babun 发行包。

安装Babun十分简单,解压发行包之后,执行里面的install.bat批处理脚本,然后静静等待执行结束即可,安装结束后Babun会自动运行。Babun默认安装在%USER_HOME%\.babun目录,似乎可以通过cmd命令行执行install.bat脚本时传递/target/t参数来指定安装目录,比如install.bat /t c:\babun(注意,安装目录最好不要有空格,这是cygwin要求的)

安装后:

  • 默认的终端模拟器是Mintty
  • Babun默认集成了Vim,如果想要安装Emacs,则执行pact install emacs(不过安装的是一个纯命令行版本的Emacs,emacs-nox)

2.2. 体验

安装完后,首先要测试一下是否安装成功,一般需要以下两个命令检查:

1
2
babun check #<==用于判断环境是否正确
babun update #<==用于判断是否有新的更新包


3. 自带的工具

3.1. 三个高效率命令

假如你是一个OS X用户,应该知道下面这三个命令的使用吧。用open调用默认程序去打开一个文件,或者在终端中使用open .在Finder打开当前目录。更常用的是把命令的输出重定向到pbcopy,实现复制到剪贴板,或者用pbpaste把剪贴板中的文本输出。

而Babun默认就提供了这三个可以让人效率大增的命令,这不得不让人对作者的细致入微更加钦佩。

3.2. 脚本解释器

Babun内置了bash、Python、Perl等解释器。比如,如果你擅长Python,那在Babun中默认是没有给Python带上pip的,所以需要在Babun中为Python加上包管理,直接执行下面这个命令即可:

1
wget https://bootstrap.pypa.io/get-pip.py -O - | python

有了pip,Python开发者就可以自由的安装诸如ipython之类的东西,还有包罗万象的类库。

3.3. oh-my-zsh

Babun默认是安装了oh-my-zshd的。在这里可以使用oh-my-zsh的各种插件,根据需求自己配置。


4. 常用配置

4.1. 适应网络环境的配置

Babun的配置文件是~/.babunrc。为了适应工作场景中的网络环境,需要对配置文件进行如下修改。

关掉Babun每次启动时的自动检测:

1
2
# Uncomment this to disable daily auto-update & proxy checks on startup (not recommended!)
export DISABLE_CHECK_ON_STARTUP="true"

这么做可以加快Babun的启动速度。如果有需要,可以通过babun check来进行手动检查。

4.2. 代理配置

代理设置(根据个人情况设置):

1
2
3
4
5
# Uncomment this lines to set up your proxy
export http_proxy='xxx'
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export no_proxy=localhost;xxx

4.3. 字符编码设置

Babun默认编码是UTF-8,而Windows的cmd命令输出是GBK编码的,所以在Babun里面运行ipconfig等Windows命令时,中文的显示会是一大堆乱码。

虽然也可以把Babun的字符编码改成GBK,但是在bash等环境中的中文名又会出现乱码了。最好是在Babun环境中使用UTF-8编码,ipconfig等Windows指令用cmder或默认cmd执行就行了。

4.4. 默认使用zsh

1
%userprofile%\.babun\cygwin\bin\mintty.exe /bin/env CHERE_INVOKING=1 /bin/zsh.exe

4.5. 使用自定义mintty配置

1
%userprofile%.babun\cygwin\bin\mintty.exe -t "%userprofile%.babun\cygwin\etc\minttyrc"

保存后,建立一个新终端时选Babun就可以了。

配置个性化的mintty:

1
2
3
4
5
6
vim ~/.minttyrc
CursorType=block
Term=xterm-256color
Font=Source Code Pro Semibold
FontHeight=10


5. 包管理器使用

Babun提供了一个叫做pact的包管理工具,类似于Linux上面的apt-getyum的包管理工具。

5.1. pact使用语法

使用语法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pact: Installs and removes Cygwin packages.
Usage:
"pact install " to install given packages
"pact remove " to remove given packages
"pact update " to update given packages
"pact show" to show installed packages
"pact find " to find packages matching patterns
"pact describe " to describe packages matching patterns
"pact packageof " to locate parent packages
"pact invalidate" to invalidate pact caches (setup.ini, etc.)
Options:
--mirror, -m : set mirror
--invalidate, -i : invalidates pact caches (setup.ini, etc.)
--force, -f : force the execution
--help
--version

5.2. 常用软件的安装

  • 安装tmux : pact install tmux
  • 安装screen : pact install screen
  • 安装zip : pact install zip
  • 安装svn : pact install subversion
  • 安装lftp : pact install lftp
  • 安装p7zip : pact install p7zip
  • 基于openssl的socks https代理 : pact install connect-proxy
  • 安装Linux基础命令行工具more/col/whereis等命令 : pact install util-linux
  • 安装dig :pact install bind-utils
  • 安装Telnet等常用网络命令 : pact install inetutils
  • 安装Python环境 : pact install pythonpact install python-crypto

可见,这个包管理很方便,用法也简单,按照自己的需求来安装软件吧!


关于Babun就介绍这么多,希望这个工具能为你的工作提供帮助。

0%